package com.xt.partjobback.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.xt.partjobback.entity.Message;
import com.xt.partjobback.mapper.MessageMapper;
import com.xt.partjobback.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author leotong
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    private final MessageMapper messageMapper;
    @Autowired
    public MessageServiceImpl(MessageMapper messageMapper) {
        this.messageMapper = messageMapper;
    }

    @Override
    public Message getMessage() {
        QueryWrapper<Message> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderBy(true,false,"createTime");
        return messageMapper.selectList(queryWrapper).get(0);
    }

    @Override
    public Page<Message> getMessageByPage(Message message) {
        Page<Message> page=new Page<>(message.pageNum==null?1: message.getPageNum(),message.pageSize==null?5: message.getPageSize());
        QueryWrapper<Message> queryWrapper=new QueryWrapper<>();
        if (message.getContent()!=null){
            queryWrapper.like("content",message.getContent());
        }
        return messageMapper.selectPage(page, queryWrapper);
    }
}
